package com.stylefeng.guns.core.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class EnableCountTimeAspect {

    @Pointcut(value ="@annotation(com.stylefeng.guns.common.annotion.CmputerTime)")
    public void cutService() {
    }

    @Around("cutService()")
    public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
        long begin = System.currentTimeMillis();
        Object obj = pjp.proceed();
        String methodName = pjp.getSignature().getName();
        String className = pjp.getSignature().getDeclaringTypeName();
        System.out.println(className + "." + methodName + " 方法消耗时间：" + (System.currentTimeMillis() - begin) + " ms");
        return obj;
    }
}
